import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },


  {
    path: '/transfer',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'transfer',
        component: () => import('@/views/transfer/index'),
        meta: { title: '人事调动', icon: 'nested' }
      }
    ]
  },
  {
    path:'/',
    component:Layout,
    redirect:'/info',
    children:[
      {
        path:'info',
        name:'Info',
        component:()=>import('@/views/info/index'),
        meta: { title: '个人中心', icon: 'form' }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: '/personnel',
    redirect:'/personnel/das',
    component: Layout,
    meta: { title: '员工管理', icon: 'nested'},
    children: [
      {
        path: 'das',
        name: 'das',
        component: () => import('@/views/personnel/index'),
        meta: { title: '员工基本信息', icon: 'form' }
      },
      {
        path: 'header',
        name: 'header',
        component: () => import('@/views/personnel/header'),
        meta: { title: '证件照管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/contract',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'contract',
        component: () => import('@/views/contract/index'),
        meta: { title: '合同管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/training',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'training',
        component: () => import('@/views/training/index'),
        meta: { title: '培训管理', icon: 'user' }
      }
    ]
  },

  {
    path: '/salary',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'salary',
        component: () => import('@/views/salary/index'),
        meta: { title: '薪酬管理', icon: 'table' }
      }
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
